<?php
declare (strict_types = 1);

namespace app\admin\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Purchase extends Model
{
    
    protected $schema = [
        'id' => 'int',
        'name' => 'string',
        'pic' => 'string',
        'material' => 'string',
        'manufacturer' => 'string',
        'shop_no' => 'string',
        'buying_price' => 'string',
        'price_adjustment_date' => 'string',
        'create_time' => 'int',
        'uid' => 'string',
        'num' => 'int',
        'box_gauge' => 'string',
        'notes' => 'string',
        'status' => 'int',
    ];

    public function adjustment() {
        return $this->hasMany(Adjustment::class, 'purchase_id', 'id');
    }

    public function delProduct($ids)
    {
        return Product::destroy($ids);
    }

    public function getProductJoinSku()
    {
        $result = Db::table('lm_product')
        ->alias('p')
        ->join('lm_sku s', 'p.id = s.product_id', 'LEFT')
        ->select()->toArray();
        halt($result);
        return $result;
    }
}
